package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 1、获取spu分页列表
 */
@RestController
@RequestMapping("/admin/product")
@Api(tags = "获取品牌列表")
public class BaseTrateController {
    //http://api.gmall.com/admin/product/{page}/{limit}?category3Id=61
    //get
    //返回的是一个集合数据
    @Autowired
    BaseTrademarkService  baseTrademarkService ;

    @ApiOperation("分页获取品牌列表")
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result getTrademark(@PathVariable("page") Long page,
                               @PathVariable("limit") Long limit){
        Page<BaseTrademark> pages = new Page<>(page,limit);

        //分页信息、查到的结果
        Page<BaseTrademark> result = baseTrademarkService.page(pages);

        return Result.ok(result);
    }
   // http://api.gmall.com/admin/product/baseTrademark/save
    //返回值	{code: 200, message: "成功", data: null, ok: true}
    @ApiOperation( "添加品牌")
    @PostMapping("/baseTrademark/save")
    public  Result saveSpuInfo(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return  Result.ok();

    }
    @ApiOperation("删除品牌")
    @DeleteMapping("baseTrademark/remove/{id}")
    public Result deleteTrakeById(@PathVariable Long id){
        baseTrademarkService.removeById(id);
        return  Result.ok();
    }
    //5、根据Id获取品牌
    @ApiOperation("获取品牌")
    @GetMapping("/baseTrademark/get/{id}")
  public  Result  getTrankById(@PathVariable Long id){
        BaseTrademark trademark = baseTrademarkService.getById(id);
        return  Result.ok(trademark);
    }
    @ApiOperation("修改品牌")
    @PutMapping("/baseTrademark/update")
    public Result  UpdateTrankById(@RequestBody  BaseTrademark  baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return  Result.ok();
    }
    /**
     * 获取品牌属性列表
     * @return
     */
    @GetMapping("/baseTrademark/getTrademarkList")
    public  Result  getTrademarkList(){
        List<BaseTrademark> baseTrademarks = baseTrademarkService.list();
        return  Result.ok(baseTrademarks);
    }


}
